package com.dormitory.management.system.DAO;
import com.dormitory.management.system.entity.StudentExcel;
import com.dormitory.management.system.req.StudentSaveReq;
import com.dormitory.management.system.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UpLoadStudentExcelFileDao {

    @Autowired
    @Lazy
    StudentService studentService;

    public void save(List<StudentExcel> list) {
        // 调用mapper对象的batchInsert进行批量插入
        System.out.println(list);
        for(int i=0;i<list.size();i++){

            StudentSaveReq req = new StudentSaveReq();

            req.setStuId(list.get(i).getStuId());
            req.setName(list.get(i).getName());
            if("男".equals(list.get(i).getSex()))req.setSex(0);
            if("女".equals(list.get(i).getSex()))req.setSex(1);
            req.setStuClass(list.get(i).getStuClass());
            req.setEmail(list.get(i).getEmail());
            req.setPhone(list.get(i).getPhone());

            if(list.get(i).getAge()!=null)req.setAge(list.get(i).getAge());
            if(list.get(i).getMajor()!=null)req.setMajor(list.get(i).getMajor());
            if(list.get(i).getDepartment()!=null)req.setDepartment(list.get(i).getDepartment());
            if(list.get(i).getBirthDate()!=null)req.setBirthDate(list.get(i).getBirthDate());
            if(list.get(i).getAddress()!=null)req.setAddress(list.get(i).getAddress());
            studentService.save(req);
        }

    }
}